from rest_framework import serializers
from django.contrib.auth.models import Permission
from django.contrib.auth.models import ContentType


class PermissionSerializer(serializers.ModelSerializer):
    # content_type = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = Permission
        fields = ("id","name","codename","content_type")
# {
#     "counts": "权限总数量",
#     "list": [
#         {
#             "id": "权限id",
#             "name": "权限名称",
#             "codename": "权限识别名",
#             "content_type": "权限类型"
#         },
#         ...
#     ],
#     "page": "当前页码",
#     "pages": "总页码",
#     "pagesize": "页容量"
# }
# codename: "can_chifan"
# # content_type: 6
# name: "chifan"


class PermissionTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = ContentType
        fields = ("id","name")

  # [
  #       {
  #           "id": "权限类型id",
  #           "name": "权限类型名称"
  #       },
  #       ...
  #   ]